package controller.link;

import view.client.Console;
import java.io.Serializable;
import controller.Link;
import model.User;
import model.Attendant;
import model.Server;

public class Register implements Link, Serializable {

    private String name;
    private boolean accepted;
    private String message;

    public Register(String name) {
        this.name = name;
    }

    @Override
    public void serverUse(Server server, Attendant at) {
        User user;
        boolean aux = server.testName(name);
        if (aux) {
            server.sendToConsole(name + " se conectou");
            user = new User(name, server.getWorld(), server);
            server.setUser(user);
            server.addUser(user);
            this.accepted = true;
            server.setRegister(this);
        } else {
            this.accepted = false;
            this.message = "Nickname já está em uso";
            server.setRegister(this);
        }
    }

    @Override
    public void clientUse(Console console) {
    }

    public boolean isAccepted() {
        return accepted;
    }
}
